#include "Util.h"
#include <glad/glad.h>
#include <string>
#include <SEDebug/Log/Log.h>

namespace SEngine
{

    void glCheckError_(const char * file, int line)
    {
        GLenum errorCode;
        while ((errorCode = glGetError()) != GL_NO_ERROR)
        {
            std::string error;
            switch (errorCode)
            {
                case GL_INVALID_ENUM:                  error = "INVALID_ENUM"; break;
                case GL_INVALID_VALUE:                 error = "INVALID_VALUE"; break;
                case GL_INVALID_OPERATION:             error = "INVALID_OPERATION"; break;
                case GL_OUT_OF_MEMORY:                 error = "OUT_OF_MEMORY"; break;
                case GL_INVALID_FRAMEBUFFER_OPERATION: error = "INVALID_FRAMEBUFFER_OPERATION"; break;
            }
            Log::GetInstance().Warn("{} {} {}", file, line, error);
        }
    }

    void glClearError_()
    {
        GLenum errorCode;
        while ((errorCode = glGetError()) != GL_NO_ERROR) {}
    }

} // namespace SEngine
